<?php
/**
 * +----------------------------------------------------------------------
 * | 模型
 * +----------------------------------------------------------------------
 *                      _ooOoo_
 *                     o8888888o            | AUTHOR: 杜云
 *                     88" . "88            | EMAIL: 987772927@qq.com
 *                     (| -_- |)            | QQ: 987772927
 *                     O\  =  /O            | WECHAT: 987772927
 *                  ____/`---'\____
 *                .'  \\|     |//  `.
 *               /  \\|||  :  |||//  \
 *              /  _||||| -:- |||||-  \
 *              |   | \\\  -  /// |   |
 *              | \_|  ''\-/''  |   |
 *              \  .-\__  `-`  ___/-. /
 *            ___`. .'  /-.-\  `. . __
 *         ."" '<  `.___\_<|>_/___.'  >'"".
 *        | | :  `- \`.;`\ _ /`;.`/ - ` : | |
 *        \  \ `-.   \_ __\ /__ _/   .-` /  /
 *   ======`-.____`-.___\_____/___.-`____.-'======
 *                      `=-='
 * +----------------------------------------------------------------------
 */
declare (strict_types=1);

namespace App\Model;

use Hyperf\Database\Model\SoftDeletes;

class Roles extends BaseModel
{
    use SoftDeletes;
    protected $table = 'roles';

    protected $fillable = [
        'name',
        'data_permission_type',
        'data_permission_rules',
        'console_view',
        'console_module',
        'remark',
        'sort',
        'status',
        'created_user',
        'created_at',
        'updated_at',
    ];

    protected $casts = [
        'console_module'  => 'array',
        'data_permission_rules'  => 'array',
        'data_permission_type'  => 'integer',
        'sort'   => 'integer',
        'status'   => 'integer',
    ];

    protected $hidden = [
        'deleted_at'
    ];
    public function users()
    {
        return $this->belongsToMany(user::class,'users_roles','role_id','user_id');
    }
    public function menus()
    {
        return $this->belongsToMany(Menus::class,'roles_menus','role_id','menu_id');
    }
}
